﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Windows.Forms;
using System.Data;

namespace DAO
{
    class DataProvider
    {
        static SqlConnection connect = null;
         static  DataProvider()
        {
            string connectString = @"Data Source=AD-PC\THUNGMY;Initial Catalog=QUANLYNHAHANG_2;Integrated Security=True";
         connect = new SqlConnection(connectString);
        }
        public static DataTable ExcuteQuery ( string strQuery ) 
        {
            DataTable dt = null;
            try
            {
                connect.Open();
                SqlDataAdapter da = new SqlDataAdapter(strQuery, connect);
                dt = new DataTable();
                da.Fill(dt);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Thuc thi cau lenh bi loi " + ex.ToString());
            }
            finally
            {
                connect.Close();
            }
            return dt;
        }
        public static int ExcuteNonQuery(string strQuery)
        {
            int kq = 0;
            try
            {
                connect.Open();
                SqlCommand cmd = new SqlCommand(strQuery, connect);
                kq = cmd.ExecuteNonQuery();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Loi khi thuc thi noneQuery " + ex.ToString());
            }
            finally
            {
                connect.Close();
            }
            return kq;
        }
        public static DataTable ExcuteProdurce(string strQuery )
        {
            return null;
        }
    }
    
}
